package com.evildog.workspace.invest.application.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.evildog.workspace.dependencies.mybatis.object.QueryConditionDTO;
import com.evildog.workspace.dependencies.mybatis.util.QueryConditionUtils;
import org.springframework.util.Assert;
import com.evildog.workspace.common.object.PageQuery;
import com.evildog.workspace.common.result.PagedResult;
import com.evildog.workspace.invest.application.dto.BillTypeCategoryPageDTO;
import com.evildog.workspace.invest.application.dto.BillTypeCategoryListDTO;
import com.evildog.workspace.invest.application.dto.BillTypeCategoryDTO;
import com.evildog.workspace.invest.application.bo.BillTypeCategoryBO;
import com.evildog.workspace.invest.application.bo.BillTypeCategoryPageBO;
import com.evildog.workspace.invest.application.bo.BillTypeCategoryListBO;
import com.evildog.workspace.invest.application.convert.BillTypeCategoryConvert;
import java.util.List;
import com.evildog.workspace.invest.application.entity.BillTypeCategory;
import com.evildog.workspace.invest.application.entity.BillTypeCategoryPageDO;
import com.evildog.workspace.invest.application.entity.BillTypeCategoryListDO;
import com.evildog.workspace.invest.application.mapper.BillTypeCategoryMapper;
import com.evildog.workspace.invest.application.service.BillTypeCategoryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

@Service
public class BillTypeCategoryServiceImpl extends ServiceImpl<BillTypeCategoryMapper, BillTypeCategory> implements BillTypeCategoryService {

    @Override
    public PagedResult<BillTypeCategoryPageBO> getPageList(PageQuery query, List<QueryConditionDTO> queryConditions, BillTypeCategoryPageDTO pageDTO) {
        IPage<BillTypeCategoryPageDO> page = this.baseMapper.getPageList(
                QueryConditionUtils.getPagination(query),
                queryConditions,
                pageDTO);
        return BillTypeCategoryConvert.INSTANCE.convert(page);
    }

    @Override
    public List<BillTypeCategoryListBO> getList(List<QueryConditionDTO> queryCondition, BillTypeCategoryListDTO dto) {
        List<BillTypeCategoryListDO> billTypeCategoryList = this.baseMapper.getList(queryCondition, dto);
        return BillTypeCategoryConvert.INSTANCE.convert(billTypeCategoryList);
    }

    @Override
    public BillTypeCategoryBO getDetailById(Long id) {
        BillTypeCategory billTypeCategory = getById(id);
        Assert.notNull(billTypeCategory, "billTypeCategory is null!");
        return BillTypeCategoryConvert.INSTANCE.convert(billTypeCategory);
    }

    @Override
    public boolean save(BillTypeCategoryDTO dto){
        BillTypeCategory newBillTypeCategory = BillTypeCategoryConvert.INSTANCE.convert(dto);
        return save(newBillTypeCategory);
    }

    @Override
    public boolean updateById(Long id, BillTypeCategoryDTO dto){
        BillTypeCategory oldBillTypeCategory = getById(id);
        Assert.notNull(oldBillTypeCategory, "billTypeCategory is null!");
        BillTypeCategory newBillTypeCategory = BillTypeCategoryConvert.INSTANCE.convert(dto);
        newBillTypeCategory.setId(id);
        return updateById(newBillTypeCategory);
    }
}
